{% extends './layout.html'%} {%block main%}
<style>
	h6 {
		margin-bottom: 5px;
	}
	i.qrcode{
		cursor: pointer;
	}
	#qrcode{
		text-align: center;
		padding : 20px 40px;
		display: none;
	}
	#qrcode p{
		padding-top:30px;
	}
    #pager{
        text-align: center;
    }
</style>
<blockquote class="layui-elem-quote news_search layui-form">
	<form action="">
	<input type=hidden name=page value='{{page}}'>
	<div class="layui-inline">
		<div class="layui-input-inline">
			<h6>手机号</h6>
			<input type="text" name=phone value="{{phone}}" placeholder="手机号" class="layui-input search_input">
		</div>

	</div>
    <div class="layui-inline">
		<div class="layui-input-inline">
			<h6>昵称</h6>
			<input type="text" name=nickname value="{{nickname}}" placeholder="昵称" class="layui-input search_input">
		</div>

	</div>

	<div class="layui-inline">
		<div class="layui-input-inline">
			<h6>开始时间</h6>
			<input type="text" name=start_time id=start_time value="{{start_time if start_time != '1970-01-01' else ''}}" placeholder="开始时间" class="layui-input search_input">
		</div>
	</div>

	<div class="layui-inline">
		<div class="layui-input-inline">
			<h6>结束时间</h6>
			<input type="text" name=end_time id=end_time value="{{end_time if end_time != '2099-01-01' else ''}}" placeholder="结束时间" class="layui-input search_input">
		</div>
	</div>
	<div class="layui-inline">
		<div class="layui-input-inline">
			<h6>所属单位</h6>

			<select name="parent_id" lay-verify="" lay-search>
				<option value="">不限</option>
				{%for item in children%}
				<option value="{{item.id}}" {{'selected' if item.id == parent_id}}>{%if item.type == 'normal'%} 【综合会员】 {%elif item.type == 'jingji'%} 【经纪会员】 {%elif item.type == 'jujian'%} 【居间代理】 {%elif item.type == 'jigou'%} 【机构代理】 {%endif%} {{item.nickname}}</option>
				{%endfor%}
			</select>
		</div>
	</div>
    <div class="layui-inline">
		<div class="layui-input-inline">
			<h6>直属</h6>
            <input type="checkbox" {{'checked' if zhishu}} name="zhishu" lay-skin="switch" lay-text="直属|不限">
		</div>
	</div>

	<div class="layui-inline" style=''>
		<h6>&nbsp;</h6>
		<a class="layui-btn layui-btn-normal" onclick='$("form").submit()'>查询</a>
		<a class="layui-btn addJingji">添加</a>
	</div>
	</form>
	<!--<div class="layui-input-inline">
			<input type="text" value="" placeholder="开始时间" class="layui-input search_input">
		</div>
		<div class="layui-input-inline">
			<input type="text" value="" placeholder="结束时间" class="layui-input search_input">
		</div>
		<div class="layui-input-inline">
			<input type="text" value="" placeholder="所属单位" class="layui-input search_input">
		</div>
		<a class="layui-btn search_btn">查询</a>-->
</blockquote>

<div class="layui-form news_list">
	<table class="layui-table">

		<thead>
			<tr>
				<th style="text-align:left;">
					序号</th>
				<th>昵称</th>
				<th>手机号</th>
				<th>创建时间</th>
                <th>所属单位</th>
				<th>余额</th>
				<th>操作</th>
			</tr>
		</thead>

		<tbody class="news_content">
			{%for item in list%}
			<tr>
				<td>{{loop.index + (page - 1) * 20}}</td>
				<td>{{item.nickname}}</td>
				<td>
					{{item.phone}}
				</td>
				<td>
					{{item.add_time | sdate}}
				</td>
				<td>
					{{item.parent.nickname}}
				</td>
	
				<td>
				{%if item.member %}
					{{item.member.available_predeposit}}
				{%else%}
					0
				{%endif%}
				</td>
				
				<td>
					<a href="javascript:;" data-id='{{item.id}}' class="show layui-btn layui-btn-mini layui-btn-normal">查看</a>
					{% if proxy.id == 1 %}
					<a href="javascript:;" data-id='{{item.id}}' style='' class="transfer layui-btn layui-btn-mini layui-btn-normal">转移</a>
					{% endif %}
				</td>
				

			</tr>
			{%endfor%}
		</tbody>
	</table>
</div>

<div id='pager'></div>

{%endblock%} {%block js%}
<script src='/static/js/qrcode.js'></script>
<script>
	layui.use(["laydate", "element", "form","laypage"], function(laydate, ele, form,laypage) {
		//执行一个laydate实例
		laydate.render({
			elem: '#start_time' //指定元素
		});

		laydate.render({
			elem: '#end_time' //指定元素
		});
		
		laypage.render({
			elem: 'pager',
			count: '{{count}}' ,//数据总数，从服务端得到
			limit:20	,
            curr :'{{page}}',
			jump: function(obj, first) {
				//obj包含了当前分页的所有参数，比如：
				console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
				console.log(obj.limit); //得到每页显示的条数

				//首次不执行
				if(!first) {
					$('input[name=page]').val(obj.curr);
					$("form").submit();
					//do something
				}
			}
		});
		
		$('.show[data-id]').click(function(){
			openWindow("查看","/proxy/member_detail.html?id=" + $(this).data("id"))
		});
		
		$('.transfer[data-id]').click(function(){
			openWindow("会员转移",'/proxy/transfer.html?type=member&id='+$(this).attr('data-id'));
		});

		form.on("select(action)", function(data) {
			var val = data.value;
			if(val == '') {
				return;
			}
			var id = $(data.elem).attr('data-id');
			switch(val) {
				case 'edit':
					openWindow("编辑", "/proxy/addMember.html?id=" + id)
					break;
					
				case 'login_pass':
					layer.prompt({title: '输入新密码', formType: 1}, function(pass, index){
					  	var index = layer.load();
			  			layer.closeAll();
					  	
					  	$.post("/proxy/api/modify_password",{
					  		id : id,
					  		pass : pass,
					  		"type" : "login"
					  	},function(msg){
					  		if(msg.success){
								layer.msg("修改成功",{icon : 1})
					  		}
					  		else{
					  			layer.msg("修改失败",{icon : 2})
					  		}
					  	},'json');
					});
					break;
					
				case 'pay_pass':
					layer.prompt({title: '输入新密码', formType: 1}, function(pass, index){
					  	var index = layer.load();
			  			layer.closeAll();
					  	
					  	$.post("/proxy/api/modify_password",{
					  		id : id,
					  		pass : pass,
					  		type : "pay"
					  	},function(msg){
					  		if(msg.success){
								layer.msg("修改成功",{icon : 1})
					  		}
					  		else{
					  			layer.msg("修改失败",{icon : 2})
					  		}
					  	},'json');
					});
					break;
					
				case 'zhuanyi':
					break;
			}
			$(data.othis).parent().find("[lay-value='']").trigger('click');
			//			alert(1)
		});
	});

	function openWindow(title, href) {
		var index = layui.layer.open({
			title: title,
			type: 2,
			content: href,
			success: function(layero, index) {
				setTimeout(function() {
					//layui.layer.tips('点击此处返回', '.layui-layer-setwin .layui-layer-close', {
					//	tips: 3
					//});

					var iframe = $('iframe');
					var body = $(iframe.contents()).find("body");
					iframe.height($(window).height() - 100)
				}, 100);
			}
		})

		layui.layer.full(index);
	}

	$(function() {

		
		$('.qrcode').click(function(){
			var id = $(this).attr('data-id');

			var url = "http://www.baidu.com/s" + id
			$('#qrcode > div').html("").qrcode({
				width: 200,
				height:200,
				text: url
			});
			
			$('#qrcode > p').html(url);

			layui.layer.open({
				type : 1,
				content : $('#qrcode'),
				title : "推广二维码"
			});
		});

		$(window).one("resize", function() {
			$('.addJingji').click(function() {
				openWindow("添加", "/proxy/addMember.html?");
			});
		}).resize();
	})
</script>
{%endblock%}